<?php

if (!defined("JOYEASY"))
    exit("Access Denied");

class IndexAction extends BaseAction {

    public function index() {
        $this->assign('bcid', 0); //顶级栏目 
        $this->display();
    }
    public function home() {
        $this->assign('bcid', 0); //顶级栏目 
        $this->display();
    }
	function baoming(){
		if($_POST['title']=='' || $_POST['sex']=='' || $_POST['nian']=='' || $_POST['yue']=='' || $_POST['ri']=='' || $_POST['banji']=='' || $_POST['kanhu']=='' || $_POST['zhuzhi']=='' || $_POST['jiazhang']=='' || $_POST['dianhua']==''){
            $this->error("带*号为必填项");
			
		}else{
			$baoming=M('baoming');
			$_POST['createtime']=time();
			$_POST['status']=1;
			$_POST['userid']=1;
			$_POST['lang']=1;
			if($baoming->add($_POST)){
				$this->success("提交申请成功");
			}else{
				$this->error("提交申请失败");
			}
		}
		
	}

	function wenjuando(){
		if($_POST['yuansuo']==0 || $_POST['banji']==0){
            $this->error("请选择所在园所与班级");
			
		}else{
			
			//判断园所和班级名称
			$yuansuo=M('category')->find($_POST['yuansuo']);
			$yuansuoming=$yuansuo['catname'];
			$banji=M('banji')->find($_POST['banji']);
			$banjiming=$banji['title'];
			$wenjuantiid=$_POST['wenjuantiid'];//问卷题id
			//问卷名称：园所名+班级名
			$wenjuan['title']=$yuansuoming.$banjiming;
			$diyidati=M('category')->where("parentid=".$wenjuantiid." and moduleid=21")->find();
			$wenjuan['yidabiaoti']=$diyidati['catname'];
			$wenjuan['yidayuanyin']=$_POST['diyidajianyi'];
			
			$dierdati=M('category')->where("parentid=".$wenjuantiid." and moduleid=23")->find();
			$wenjuan['erdabiaoti']=$dierdati['catname'];
			$wenjuan['erdayuanyin']=$_POST['dierdajianyi'];

			$wenjuan['qita']=$_POST['qitayijian'];
			$wenjuan['createtime']=time();
			$wenjuan['status']=1;
			$wenjuan['userid']=1;
			$wenjuan['lang']=1;
			$wenjuan['catid']=$_POST['wenjuantiid'];
			if($dcjieguo=M('dcjieguo')->add($wenjuan)){

				$diyixiao=M('danxuan')->where("catid=".$diyidati['id']."")->select();
				foreach($diyixiao as $k=>$v){
					$diyixiaodaan['title']=$v['title'];
					if($_POST['diyixiaoyuanyin'.$v['id'].'']==''){
						$diyixiaodaan['daan']=$_POST['diyixiaoxuan'.$v['id'].''];
					}else{
						$diyixiaodaan['daan']=$_POST['diyixiaoxuan'.$v['id'].''].",".$_POST['diyixiaoyuanyin'.$v['id'].''];
					}
					$diyixiaodaan['dcjieguo_id']=$dcjieguo;
					M('dcdaan')->add($diyixiaodaan);//添加第一大题各小题答案至dadaan
				}
				//$dierxiao=M('danxuan')->where("catid=".$dierdati['id']."")->limit(0,3)->select();
				$jiaoshi=M('jiaoshi')->where("ban_id=".$banji['id']."")->select();//查询本班级教师
				
				foreach($jiaoshi as $k=>$v){
					$dierxiaodaan1['title']=$v['title'].",".$_POST['diertititle1'];
					$dierxiaodaan2['title']=$v['title'].",".$_POST['diertititle2'];
					$dierxiaodaan3['title']=$v['title'].",".$_POST['diertititle3'];
					$dierxiaodaan1['daan']=$_POST['dierxiaoxuan1'.$v['id'].''];
					$dierxiaodaan2['daan']=$_POST['dierxiaoxuan2'.$v['id'].''];
					$dierxiaodaan3['daan']=$_POST['dierxiaoxuan3'.$v['id'].''];
					$dierxiaodaan1['dcjieguo_id']=$dcjieguo;
					$dierxiaodaan2['dcjieguo_id']=$dcjieguo;
					$dierxiaodaan3['dcjieguo_id']=$dcjieguo;
					M('dcdaan')->add($dierxiaodaan1);//添加第二大题 各老师 第一项评价
					M('dcdaan')->add($dierxiaodaan2);//添加第二大题 各老师 第二项评价
					M('dcdaan')->add($dierxiaodaan3);//添加第二大题 各老师 第三项评价
				}
				
				$disandati=M('category')->where("parentid=".$wenjuantiid." and moduleid=24")->find();
				$disanxiao=M('jsping')->where("catid=".$disandati['id']."")->select();
				foreach($disanxiao as $k=>$v){
					$disanxiaodaan['title']=$v['title'];
					$disanxiaodaan['daan']=$_POST['disanxiao'.$v['id'].''];
					$disanxiaodaan['dcjieguo_id']=$dcjieguo;
					M('dcdaan')->add($disanxiaodaan);//添加第三大题各小题答案至dadaan
				}
				
				$disidati=M('category')->where("parentid=".$wenjuantiid." and moduleid=22")->find();
				$disixiao=M('duoxuan')->where("catid=".$disidati['id']."")->select();
				foreach($disixiao as $k=>$v){
					$disixiaodaan['title']=$v['title'];
					foreach($_POST['disixiao'.$v['id'].''] as $kk=>$vv){
						$disixiaoxuanxiang.=$vv.",";
					}
					if($_POST['disixiaoqita'.$v['id'].'']==''){
						$disixiaodaan['daan']=$disixiaoxuanxiang;
					}else{
						$disixiaodaan['daan']=$disixiaoxuanxiang.",其他、".$_POST['disixiaoqita'.$v['id'].''];
					}
					$disixiaodaan['dcjieguo_id']=$dcjieguo;
					M('dcdaan')->add($disixiaodaan);//添加第一大题各小题答案至dadaan
				}
				
				$this->success("提交成功");
			}else{
				$this->error("提交失败");
			}
		}
		
	}

	function wenjuan(){
	
        $this->display();
		
	}

    public function show_banji() {
		$yuan_id=$_POST['yuan_id'];
		$banji=M('banji')->where("yuan_id=".$yuan_id."")->select();
		$banjioption="<option value='0'>班级</option>";
		foreach($banji as $k=>$v){
			$banjioption.="<option value='".$v['id']."'>".$v['title']."</option>";
		}
		echo $banjioption;
		exit;
    }
    public function show_jiaoshi() {
		$ban_id=$_POST['ban_id'];
		$jiaoshi=M('jiaoshi')->where("ban_id=".$ban_id."")->select();
		foreach($jiaoshi as $k=>$v){
			$jiaoshioption.="
				<div style=\"width:814px;height:30px;border-bottom:1px solid #333;line-height:30px;text-align:center;\">
					<div class=\"diyixiao\"  style=\"width:129px;\">
					".$v['title']."
					</div>
					<div class=\"diyixiao\">
						<input name=\"dierxiaoxuan1".$v['id']."\" type=\"radio\" value=\"A\" />
						<span>A</span>
					</div>
					<div class=\"diyixiao\">
						<input name=\"dierxiaoxuan1".$v['id']."\" type=\"radio\" value=\"B\" />
						<span>B</span>
					</div>
					<div class=\"diyixiao\">
						<input name=\"dierxiaoxuan1".$v['id']."\" type=\"radio\" value=\"C\" />
						<span>C</span>
					</div>
					<div class=\"diyixiao\">
						<input name=\"dierxiaoxuan1".$v['id']."\" type=\"radio\" value=\"D\" />
						<span>D</span>
					</div>
					<div class=\"diyixiao\">
						<input name=\"dierxiaoxuan2".$v['id']."\" type=\"radio\" value=\"A\" />
						<span>A</span>
					</div>
					<div class=\"diyixiao\">
						<input name=\"dierxiaoxuan2".$v['id']."\" type=\"radio\" value=\"B\" />
						<span>B</span>
					</div>
					<div class=\"diyixiao\">
						<input name=\"dierxiaoxuan2".$v['id']."\" type=\"radio\" value=\"C\" />
						<span>C</span>
					</div>
					<div class=\"diyixiao\">
						<input name=\"dierxiaoxuan2".$v['id']."\" type=\"radio\" value=\"D\" />
						<span>D</span>
					</div>
					<div class=\"diyixiao\">
						<input name=\"dierxiaoxuan3".$v['id']."\" type=\"radio\" value=\"A\" />
						<span>A</span>
					</div>
					<div class=\"diyixiao\">
						<input name=\"dierxiaoxuan3".$v['id']."\" type=\"radio\" value=\"B\" />
						<span>B</span>
					</div>
					<div class=\"diyixiao\">
						<input name=\"dierxiaoxuan3".$v['id']."\" type=\"radio\" value=\"C\" />
						<span>C</span>
					</div>
					<div class=\"diyixiao\">
						<input name=\"dierxiaoxuan3".$v['id']."\" type=\"radio\" value=\"D\" />
						<span>D</span>
					</div>
					<div class=\"clear\"></div>
				</div>
				";
		}
		echo $jiaoshioption;
		exit;
    }

    function about_user() {
        $all_article = 0;
        $all_guest = 0;
        $all_com = 0;
        $userid = $_GET['userid'];
        $user = M("User");
        $userinfo = $user->where('id = ' . $userid)->find(); //作者信息
        $article = M("Article");
        $count = $article->where('status = 1 and userid = ' . $userid)->count();
        if ($count) {
            import("@.ORG.Page");
            $listRows = !empty($cat['pagesize']) ? $cat['pagesize'] : C('PAGE_LISTROWS');
            $page = new Page($count, $listRows);
            $pages = $page->show();
            $list = $article->where('status = 1 and userid = ' . $userid)->limit($page->firstRow . ',' . $page->listRows)->select(); //作者文章
            if (!empty($list)) {
                $avatar = M("Comment");
                foreach ($list as $key => $all) {
                    $list[$key]['com_num'] = $avatar->where('status = 1 and article_id = ' . $all['id'])->count();
                }
            }
            $this->assign('list', $list);
            $this->assign('pages', $pages);
        }
        $all_article = $article->where('status = 1 and userid = ' . $userid)->count();
        $com = M("Comment");
        $all_com = $com->where('status = 1 and userid =' . $userid)->count(); //作者评论
        $guest = M("Guestbook");
        $all_guest = $guest->where('status = 1 and user =' . $userid)->count(); //作者评论
        $this->assign('userinfo', $userinfo);
        $this->assign('all_article', $all_article);
        $this->assign('all_com', $all_com);
        $this->assign('all_guest', $all_guest);
        $this->display();
    }

    function about_com() {
        $all_article = 0;
        $all_guest = 0;
        $all_com = 0;
        $userid = $_GET['userid'];
        $user = M("User");
        $userinfo = $user->where('id = ' . $userid)->find(); //作者信息
        $article = M("Article");
        $all_article = $article->where('status = 1 and userid = ' . $userid)->count();
        $com = M("Comment");
        $all_com = $com->where('status = 1 and userid =' . $userid)->count(); //作者评论
        $count = $com->where('status = 1 and userid = ' . $userid)->count();
        if ($count) {
            import("@.ORG.Page");
            $listRows = !empty($cat['pagesize']) ? $cat['pagesize'] : C('PAGE_LISTROWS');
            $page = new Page($count, $listRows);
            $pages = $page->show();
            $list = $com->where('status = 1 and userid = ' . $userid)->limit($page->firstRow . ',' . $page->listRows)->select(); //作者文章
            $this->assign('list', $list);
            $this->assign('pages', $pages);
        }
        $list = $com->where('status = 1 and userid = ' . $userid)->select(); //作者评论
        $guest = M("Guestbook");
        $all_guest = $guest->where('status = 1 and user =' . $userid)->count(); //作者评论
        $this->assign('userinfo', $userinfo);
        $this->assign('all_article', $all_article);
        $this->assign('all_com', $all_com);
        $this->assign('all_guest', $all_guest);
        $this->display();
    }

    function about_guest() {
        $userid = $_GET['userid'];
        $all_article = 0;
        $all_guest = 0;
        $all_com = 0;
        $user = M("User");
        $userinfo = $user->where('id = ' . $userid)->find(); //作者信息
        $article = M("Article");
        $all_article = $article->where('status = 1 and userid = ' . $userid)->count();
        $com = M("Comment");
        $all_com = $com->where('status = 1 and userid =' . $userid)->count(); //作者评论
        $guest = M("Guestbook");
        $all_guest = $guest->where('status = 1 and user =' . $userid)->count(); //所有留言数
        $count = $guest->where('status = 1 and user = ' . $userid)->count();
        if ($count) {
            import("@.ORG.Page");
            $listRows = !empty($cat['pagesize']) ? $cat['pagesize'] : C('PAGE_LISTROWS');
            $page = new Page($count, $listRows);
            $pages = $page->show();
            $field = $field ? $field : 'u.avatar as avatar,u.username as name,u.id as id ,zx_guestbook.content as content,zx_guestbook.createtime as createtime';
            $list = $guest->join('`zx_user` as `u` on u.username =zx_guestbook.username')->where('zx_guestbook.user =' . $userid . ' and zx_guestbook.status = 1')->order('listorder desc,zx_guestbook.id desc')->field($field)->limit($page->firstRow . ',' . $page->listRows)->select();

            $this->assign('list', $list);
            $this->assign('pages', $pages);
        }
        $this->assign('userinfo', $userinfo);
        $this->assign('all_article', $all_article);
        $this->assign('all_com', $all_com);
        $this->assign('all_guest', $all_guest);
        $this->assign('moduleid', 8);
        $this->display();
    }

}

?>